package com.jim.aliceAgent.service.impl;

import com.alibaba.fastjson2.JSONObject;
import com.jim.aliceAgent.entity.User;
import com.jim.aliceAgent.service.AgentChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

@Service
public class AgentChatServiceImpl implements AgentChatService {

    @Autowired
    private WebClient webClient;

    @Override
    public Object requestChat(String userId, String query) {
        //TODO
        // 根据userId查询用户信息
        User user = new User("123", "jim", "123", "黄松江", "男", "杭州");

        JSONObject params = new JSONObject();
        params.put("id", user.getId());
        params.put("username", user.getUsername());
        params.put("nickname", user.getNickname());
        params.put("sex", user.getSex());
        params.put("location", user.getLocation());
        params.put("query", query);

        Mono<String> responseMono = webClient.post()
                .uri("/chat")
                .bodyValue(params)
                .retrieve()
                .bodyToMono(String.class);

        return responseMono.block();
    }
}
